﻿/*
    File name:          Gripper
    File type:          Class
    Author:             Sune Krog-Meyer 09888
    Creation date:      03-04-2011
    Description:        Contains gripperfunktions for the robot.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using i4pro_gruppe_d.ControllerCommunication;
using i4pro_gruppe_d.RobotCommunication;
using i4pro_gruppe_d.SimulatorAdaptor;

namespace i4pro_gruppe_d.Hardware
{
	public class Gripper
	{
	    private readonly IControllerCommunication _gripper;

        /// <summary>
        /// Classconstructor
        /// </summary>
        /// <param name="physical"> True if robot, false if simulator </param>
        public Gripper(bool physical)
        {
            if(physical)
            {
                _gripper = new ConcreteDLLAdaptor();       
            }
            else
            {
                _gripper = new ConcreteSimulatorAdaptor();
            }
        }

        /// <summary>
        /// Opens the gripper 100%
        /// </summary>
		public void Open()
		{
			Console.WriteLine(_gripper.openGripper() ? "Gripper Open: Succes" : "Gripper Open: Failed");
		}

        /// <summary>
        /// Closes the gripper as much as possible
        /// </summary>
		public void Close()
		{
			Console.WriteLine(_gripper.closeGripper() ? "Gripper Close: Succes" : "Gripper Close: Failed");
		}

        /// <summary>
        /// Measures the gripperwidth
        /// </summary>
        /// <returns> value of the gripperwidth in mm </returns>
		public short MeasureWidth()
		{
			short width = 0;
			_gripper.getGripperWidth(ref width);
			return (width);
		}
    }
}
